﻿using UnityEngine;
using System.Collections;

public class FishMovement : MonoBehaviour {
	
	public Vector2 movingForce;
	private Vector3 screenPoint;
	private Vector3 offset;
	Vector3 scale;
	public int level = 1;


	void Start(){
		movingForce = new Vector2 (10, 0);
		scale = new Vector3 (0.4f , 0.4f, 0.4f);
		transform.localScale = scale;

	}

	void Update(){

	}

	void FixedUpdate(){
		Vector3 pos = transform.position;
		Vector3 localScale = transform.localScale;
		if (Input.GetKey (KeyCode.LeftArrow)) {
			pos.x -= 0.05f;
			if (localScale.x < 0) {
				localScale.x *= -1.0f;
			}
		}
		if (Input.GetKey (KeyCode.RightArrow)) {
			pos.x += 0.05f;
			if (localScale.x > 0) {
				localScale.x *= -1.0f;
				}
			}
		if (Input.GetKey (KeyCode.UpArrow)) {
			pos.y += 0.05f;
		}
		if (Input.GetKey (KeyCode.DownArrow)) {
			pos.y -= 0.05f;
		}

		transform.position = pos;
		transform.localScale = localScale;

	}

	void OnMouseDown()
	{
		screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
		offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
	}
	
	void OnMouseDrag()
	{
		Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
		Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
		transform.position = curPosition;
	}

	void OnCollisionEnter2D(Collision2D collision){

	}
}

